package invoiceManager;

import javax.swing.JPanel;

import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JLabel;

import java.awt.Font;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.Serializable;
import java.util.Hashtable;

import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableModel;

import editManager.Edit;

public class InvoicePanel extends JPanel implements Serializable {
	
	private JTable table;	
	private JScrollPane scrollPane;
	private JButton btnElectronicInvoices, btnBack, btnEsupplyFile, btnFindInvoice;
	private JLabel lblNumberBilled;
	private int numberBilled;
	private File currentBatchFile;
	private InvoiceBatch currentBatch;
	private DefaultTableModel tableModel;
	private Hashtable<Integer, Invoice> invoiceDB;
	
	/**
	 * Create the panel.
	 */
	public InvoicePanel() {
		setPreferredSize(new Dimension(600, 400));
		setBackground(new Color(255, 160, 122));
		setLayout(null);
		
		btnBack = new JButton("Back");
		btnBack.setFont(new Font("Tahoma", Font.PLAIN, 11));
		btnBack.setBounds(482, 353, 89, 23);
		add(btnBack);
		
		scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 11, 425, 365);
		add(scrollPane);
		
		tableModel = new DefaultTableModel();
		tableModel.addColumn("Invoice");
		tableModel.addColumn("Customer");
		tableModel.addColumn("Customer ID");
		
		table = new JTable(tableModel);
		table.getColumnModel().getColumn(1).setPreferredWidth(160);
		scrollPane.setViewportView(table);
		
		btnFindInvoice = new JButton("Find Invoice");
		btnFindInvoice.setFont(new Font("Tahoma", Font.PLAIN, 11));
		btnFindInvoice.setBounds(467, 54, 113, 23);
		add(btnFindInvoice);
		
		btnEsupplyFile = new JButton("E-Supply File");
		btnEsupplyFile.setFont(new Font("Tahoma", Font.PLAIN, 11));
		btnEsupplyFile.setBounds(470, 122, 107, 23);
		add(btnEsupplyFile);
		
		btnElectronicInvoices = new JButton("Electronic Invoices");
		btnElectronicInvoices.setFont(new Font("Tahoma", Font.PLAIN, 11));
		btnElectronicInvoices.setBounds(458, 88, 131, 23);
		add(btnElectronicInvoices);
		
		JLabel lblTotalBilledToday = new JLabel("Total Billed Today:");
		lblTotalBilledToday.setHorizontalAlignment(SwingConstants.CENTER);
		lblTotalBilledToday.setFont(new Font("Tahoma", Font.PLAIN, 12));
		lblTotalBilledToday.setBounds(456, 12, 135, 14);
		add(lblTotalBilledToday);
		
		lblNumberBilled = new JLabel("###");
		lblNumberBilled.setHorizontalAlignment(SwingConstants.CENTER);
		lblNumberBilled.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblNumberBilled.setBounds(490, 26, 51, 17);
		add(lblNumberBilled);

	}

	public boolean checkForNew() {
		return false;
//INVOICE
	}	
	
	
	public InvoiceBatch generateInvoiceBatch() {
		currentBatchFile = new File("C:\\Users\\jedwards\\Desktop\\Development\\CCINV");
		try {
			currentBatch = new InvoiceBatch(currentBatchFile);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		updateTableData();
		return currentBatch;
	}
	
	private void updateTableData(){
		for(Invoice i : currentBatch.getBatch()){
			tableModel.addRow(new Object[]{i.getInvoiceNumber(), i.getBillLineOne(), i.getCustomerID()});
			tableModel.fireTableDataChanged();
		}
	}
	

	public JButton getBtnElectronicInvoices() {
		return btnElectronicInvoices;
	}

	public void setBtnElectronicInvoices(JButton btnElectronicInvoices) {
		this.btnElectronicInvoices = btnElectronicInvoices;
	}

	public JButton getBtnBack() {
		return btnBack;
	}

	public void setBtnBack(JButton btnBack) {
		this.btnBack = btnBack;
	}

	public JButton getBtnEsupplyFile() {
		return btnEsupplyFile;
	}

	public void setBtnEsupplyFile(JButton btnEsupplyFile) {
		this.btnEsupplyFile = btnEsupplyFile;
	}

	public JButton getBtnFindInvoice() {
		return btnFindInvoice;
	}

	public void setBtnFindInvoice(JButton btnFindInvoice) {
		this.btnFindInvoice = btnFindInvoice;
	}

	public JLabel getLblNumberBilled() {
		return lblNumberBilled;
	}

	public void setLblNumberBilled(JLabel lblNumberBilled) {
		this.lblNumberBilled = lblNumberBilled;
	}

	public JTable getTable() {
		return table;
	}

	public void setTable(JTable table) {
		this.table = table;
	}

	public DefaultTableModel getTableModel() {
		return tableModel;
	}

	public void setTableModel(DefaultTableModel tableModel) {
		this.tableModel = tableModel;
	}

	public InvoiceBatch getCurrentBatch() {
		return currentBatch;
	}

	public void setCurrentBatch(InvoiceBatch currentBatch) {
		this.currentBatch = currentBatch;
	}


}
